package com.yf.zzmusic.service.impl;

import com.yf.zzmusic.common.PageInfo;
import com.yf.zzmusic.pojo.dto.followSinger.FansPageDTO;
import com.yf.zzmusic.pojo.dto.followSinger.FollowSingerPageDTO;
import com.yf.zzmusic.pojo.entity.FollowSinger;
import com.yf.zzmusic.mapper.FollowSingerMapper;
import com.yf.zzmusic.pojo.entity.User;
import com.yf.zzmusic.service.IFollowSingerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 关注歌手表 服务实现类
 * </p>
 *
 * @author
 * @since 2024-03-13
 */
@Service
public class FollowSingerServiceImpl extends ServiceImpl<FollowSingerMapper, FollowSinger> implements IFollowSingerService {
  @Autowired
  FollowSingerMapper followSingerMapper;

  @Override
  public PageInfo<User> getFollowSingerList(FollowSingerPageDTO followSingerPageDTO) {
    Integer pageNum = followSingerPageDTO.getPageNum();
    Integer pageSize = followSingerPageDTO.getPageSize();
    if (pageNum == null) {
      pageNum = 1;
      followSingerPageDTO.setPageNum(1);
    }
    if (pageSize == null) {
      pageSize = 10;
      followSingerPageDTO.setPageSize(10);
    }
    //执行自定义查询,获取音乐列表
    if (pageNum >= 1) {
      followSingerPageDTO.setPageNum((pageNum - 1) * pageSize);
    }
    //创建返回结果集
    PageInfo<User> pageInfo = new PageInfo<>();
    //整理返回结果集
    pageInfo.setPageNum(followSingerPageDTO.getPageNum());
    pageInfo.setPageSize(followSingerPageDTO.getPageSize());
    pageInfo.setData(followSingerMapper.followSingerList(followSingerPageDTO));
    pageInfo.setTotal(followSingerMapper.followSingerListTotal(followSingerPageDTO.getUserId()));
    return pageInfo;
  }

  @Override
  public PageInfo<User> getFansList(FansPageDTO fansPageDTO) {
    Integer pageNum = fansPageDTO.getPageNum();
    Integer pageSize = fansPageDTO.getPageSize();
    if (pageNum == null) {
      pageNum = 1;
      fansPageDTO.setPageNum(1);
    }
    if (pageSize == null) {
      pageSize = 10;
      fansPageDTO.setPageSize(10);
    }
    //执行自定义查询,获取音乐列表
    if (pageNum >= 1) {
      fansPageDTO.setPageNum((pageNum - 1) * pageSize);
    }
    //创建返回结果集
    PageInfo<User> pageInfo = new PageInfo<>();
    //整理返回结果集
    pageInfo.setPageNum(fansPageDTO.getPageNum());
    pageInfo.setPageSize(fansPageDTO.getPageSize());
    pageInfo.setData(followSingerMapper.fansList(fansPageDTO));
    pageInfo.setTotal(followSingerMapper.fansListTotal(fansPageDTO.getSingerId()));
    return pageInfo;
  }

  @Override
  public boolean deleteFollowSinger(FollowSinger followSinger) {
    return followSingerMapper.deleteFollowSinger(followSinger);
  }
}
